import "reflect-metadata";
import {createConnection} from "typeorm";
import {User} from "./entity/User";
import {Config} from './entity/Config';

createConnection().then(async connection => {

    console.log("Inserting a new user into the database...");
    const user = new User();
    user.username = 'admin';
    user.password = 'admin';
    const config = new Config();
    config.username = 'admin';
    config.path = '.';
    await connection.manager.save(user);
    await connection.manager.save(config);

    console.log("Loading users from the database...");
    const users = await connection.manager.find(User);
    const configs = await connection.manager.find(Config);
    console.log("Loaded users: ", users);
    console.log("Loaded configs: ", configs);

    console.log("Here you can setup and run express/koa/any other framework.");

}).catch(error => console.log(error));